package com.gzx.spring.db.service.impl;

import com.gzx.risk.core.enums.AuthStatus;
import com.gzx.risk.core.enums.RiskNodes;
import com.gzx.risk.core.pojo.CreditAuthInfo;
import com.gzx.risk.core.pojo.UserInfo;
import com.gzx.risk.core.service.CreditService;
import com.gzx.spring.db.entity.CreditUserAuthorization;
import com.gzx.spring.db.service.CreditUserAuthorizationService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Slf4j
@Service
public class CreditServiceImpl implements CreditService {

    @Resource
    private CreditUserAuthorizationService creditUserAuthService;

    @Override
    public CreditAuthInfo getEffectAuthInfoByUid(Long uid) {
        CreditUserAuthorization byUid = creditUserAuthService.getLatestValidByUid(uid);
        if (Objects.isNull(byUid)) {
            return null;
        }
        CreditAuthInfo creditAuthInfo = new CreditAuthInfo();
        BeanUtils.copyProperties(byUid, creditAuthInfo);
        return creditAuthInfo;
    }

    @Override
    public void saveAuthInfo(CreditAuthInfo creditAuthInfo) {
        CreditUserAuthorization authInfo = new CreditUserAuthorization();
        BeanUtils.copyProperties(creditAuthInfo, authInfo);
        if (Objects.isNull(creditAuthInfo.getId())) {
            creditUserAuthService.save(authInfo);
        }else {
            creditUserAuthService.updateById(authInfo);
        }
    }
}
